package com.example.mywiseelves.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.example.mywiseelves.utils.Constants;

import java.security.PublicKey;

/**
 * @author ZJK
 * @data 2021 22
 * @description SQlite数据库,只用来对数据库的表，进行操作，不对表内数据操作
 */
public class DBHelper extends SQLiteOpenHelper {

    //用户表
    public static final String CREATE_USER ="create table user("
    +"user_name text,"//名称
    +"user_point integer,"//祈愿点
    +"user_pray integer,"//祈愿状态，一天之内祈愿一次。
    +"user_ad integer)";//广告状态，一天之内看三次广告。
    //精灵表
    public static final String CREATE_ELVES ="create table elves("
            +"elves_id integer,"    //精灵编号
            +"elves_name text,"  //精灵名称
            +"elves_unlocking integer,"    //精灵解锁状态
            +"elves_wisdom integer,"  //精灵智慧状态
            +"elves_message text,"    //精灵信息
            +"elves_image integer,"   //精灵图片
            +"elves_anim_normal integer,"   //精灵常态动画
            +"elves_anim_click integer,"    //精灵点击喂食动画
            +"elves_start integer,"    //精灵启动状态
            +"elves_point integer)"; //花费的祈愿点
    //语音表
    public static final String CREATE_VOICES ="create table voices("
            +"voice_id integer,"    //语音编号
            +"voice text)"; //语音资源
    //手势表
    //资源表
    public static final String CREATE_RESOURCES ="create table Resources("
            +"splash_id integer,"    //图片编号
            +"splash_image integer,"  //图片资源
            +"splash_states integer)"; //图片状态

    /**
     * @param context 上下文
     *  name    数据库的名字
     *  factory 数据库工厂，null
     *  version 数据库的版本
     */
    public DBHelper(@Nullable Context context) {
        super(context, Constants.DATABASE_NAME, null, Constants.VERSION_CODE);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建时的回调
        //创建字段
        /**
         * 建表，
         * **/
        db.execSQL(CREATE_USER);
        db.execSQL(CREATE_ELVES);
        db.execSQL(CREATE_RESOURCES);
        db.execSQL(CREATE_VOICES);
        Log.v("myapp","建表成功");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //升级数据库时的回调
    }
}
